package cn.wenhaha.app.log.controller;

import cn.wenhaha.app.log.bean.vo.LogHomeVo;
import cn.wenhaha.app.log.bean.vo.MappingState;
import cn.wenhaha.app.log.bean.vo.ReportWeekHome;
import cn.wenhaha.app.log.service.SyncReportService;
import cn.wenhaha.common.core.domain.AjaxV1Result;
import com.jfinal.kit.Kv;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

import static cn.wenhaha.common.core.domain.AjaxV1Result.*;

/**
 * 日志首页
 * --------
 *
 * @author ：wyndem
 * @Date ：Created in 2022-12-19 20:35
 */
@RestController
@RequestMapping("/api/v1/index")
public class HomeController {

    @Resource
    private SyncReportService syncReportService;

    @GetMapping
    public AjaxV1Result<LogHomeVo> index(){
       return newSuccess( syncReportService.simpleCount());
    }

    /**
     * <p>
     *    本周数据
     * </p>
     * @Author: Wyndem
     * @param id 映射id，为空查看全部
     * @DateTime: 2023-01-07 17:58
     */
    @GetMapping("week")
    public  AjaxV1Result<ReportWeekHome> week(@RequestParam(value = "id",required = false) Integer id ){
        return newSuccess( syncReportService.reportWeek(id));
    }

    /**
     * <p>
     *    映射 选择
     * </p>
     * @Author: Wyndem
     * @DateTime: 2023-01-07 20:42
     */
    @GetMapping("mapping")
    public AjaxV1Result<List<Kv>> mappingList(){
        return newSuccess( syncReportService.mappingList());
    }
    
    
    
    /**
     * <p>
     *    查询最近的更新对象
     *      -显示最近十条
     * </p>    
     * @Author: Wyndem
     * @DateTime: 2023-01-18 21:28
     */
    @GetMapping("state")
    public AjaxV1Result<List<MappingState>> state(){
        return newSuccess(syncReportService.state());
    }
}
